const { app, BrowserWindow } = require('electron');
const { autoUpdater } = require("electron-updater");
 
// 自定义安装界面
function createInstallWindow() {
  // 创建一个简单的窗口显示安装进度
  let installWindow = new BrowserWindow({
    width: 400,
    height: 200,
    frame: false,
    resizable: false,
    transparent: true,
    webPreferences: {
      nodeIntegration: true
    }
  });
 
  installWindow.loadFile('install.html'); // 加载显示安装进度的HTML文件
 
  // 监听更新进度事件
  autoUpdater.on('download-progress', (progressObj) => {
    let logMessage = "Installing...";
    logMessage += "\nPercent: " + progressObj.percent;
    logMessage += "\nTransferred: " + progressObj.transferred;
    logMessage += "\nTotal: " + progressObj.total;
    installWindow.webContents.executeJavaScript('setProgress(' + progressObj.percent + ')');
  });
 
  // 安装完成后关闭安装窗口
  autoUpdater.on('update-downloaded', (info) => {
    installWindow.webContents.executeJavaScript('onUpdateDownloaded()');
  });
}
 
// // 初始化更新检查
// function initAutoUpdater() {
//   autoUpdater.checkForUpdates();
// }
 

// module.exports = createInstallWindow;
// // 应用就绪
// app.on('ready', () => {
//   createInstallWindow();
//   // initAutoUpdater();
// });